package com.canvas.rabbitTest;

import com.canvas.service.search.HouseIndexMessage;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;

import java.io.IOException;
import java.util.Map;

/**
 * @Author: 宗恣
 * @Date: 2018/9/10 0010 11:40
 */
// @Component
public class OrderReceiver {

//    @RabbitListener(
//            bindings = @QueueBinding(
//                    value = @Queue(value = "order-queue", durable = "true"),
//                    exchange = @Exchange(value = "order-exchange", durable = "true", type = "topic"),
//                    key = "order.*"
//            )
//    )
//    @RabbitHandler
    public void onOrderMessage(@Payload HouseIndexMessage order, @Headers Map<String, Object> headers, Channel channel) throws IOException {

        // 消费者操作
        System.out.println("---------收到消息，开始消费---------");
        System.out.println("订单ID：" + order.getMessageId());

        long deliveryTag = (long) headers.get(AmqpHeaders.DELIVERY_TAG);
        channel.basicAck(deliveryTag, false);
    }

}
